tile=readLAS("../tests/data/NEON_D03_OSBS_DP1_405000_3276000_classified_point_cloud.laz")

tile<-tile %>% lasfilter(Z < 100)
tile<-tile %>% lasfilter(Z > 0)

#plot(tile, color="Z", colorPalette = heat.colors(50), trim=0.99)

#remove 
summary(tile)
#table(tile@data$Classification)
#ggplot(tile@data,aes(x=as.factor(Classification),y=Z)) + geom_boxplot()
#Toy file for testing
LASfile <- system.file("extdata", "MixedConifer.laz", package="lidR")
tile = readLAS(LASfile, select = "xyz", filter = "-drop_z_below 0")
col = pastel.colors(200)
knit_hooks$set(webgl = hook_webgl)
plot(tile,backend="rgl")

#add a point index
tile@data$PointID<-1:nrow(tile@data)

#Lastrees updates the cloud inplace, save data in seperate object
ptlist<-list()

You must enable Javascript to view this page properly.

Watershed

system.time(watershed<-segment_ITC(tile,algorithm = "watershed"))

##    user  system elapsed 
##   4.592   0.105   4.845
ptlist[["watershed"]]<-watershed %>% lasfilter(!is.na(treeID)) %>% .@data

Dalponte 2016

system.time(dalponte2016<-segment_ITC(tile,algorithm = "dalponte2016"))

##    user  system elapsed 
##   3.474   0.041   3.546
ptlist[["dalponte2016"]]<-dalponte2016 %>% lasfilter(!is.na(treeID)) %>% .@data

Silva 2016

system.time(silva2016<-segment_ITC(tile,algorithm = "silva2016"))

##    user  system elapsed 
##   3.485   0.053   3.672
ptlist[["silva2016"]]<-silva2016 %>% lasfilter(!is.na(treeID)) %>% .@data 

Comparison

How many tree objects

library(pander)
df<-data.frame(Algorthm=c("Watershed","Dalponte2016","Silva2016"),Total_Trees=c( max(ptlist[["watershed"]]$treeID,na.rm=T), max(ptlist[["dalponte2016"]]$treeID,na.rm=T), max(ptlist[["silva2016"]]$treeID,na.rm=T)))
pandoc.table(df,style="rmarkdown")
## 
## 
## |   Algorthm   | Total_Trees |
## |:------------:|:-----------:|
## |  Watershed   |     78      |
## | Dalponte2016 |     108     |
## |  Silva2016   |     108     |

Consensus

pdf<-melt(ptlist,id.vars=colnames(ptlist[["silva2016"]]))
head(pdf)
##          X       Y      Z PointID Classification  Zref treeID        L1
## 1 481352.0 3813013  0.000      23              2  0.33      2 watershed
## 2 481352.0 3813013  0.000      24              2  0.60      2 watershed
## 3 481352.3 3813015 15.038      25              0 15.18      2 watershed
## 4 481352.3 3813015 15.311      26              0 15.49      2 watershed
## 5 481352.2 3813014 14.762      27              0 15.02      2 watershed
## 6 481352.2 3813015 14.735      28              0 14.97      2 watershed
#Create point ID lookup table
res<-dcast(pdf,PointID~L1,value.var = "treeID")

idframe<-res %>% add_rownames() %>% select(rowname,PointID)
head(res<-res %>% select(-PointID))
##   dalponte2016 silva2016 watershed
## 1          107         5         2
## 2          107        16         2
## 3          108         5         2
## 4          108         5         2
## 5          107         5         2
## 6          108         5         2

Majority Rule

system.time(consensus<-majority_voting(res, is.relabelled = FALSE))
##    user  system elapsed 
##   4.049   0.066   4.144
#reassign to pointID
consensus_frame<-data.frame(rowname=rownames(res),consensus=consensus) %>% inner_join(idframe) %>% select(PointID,consensus)

#merge with the original tile
tile@data<-merge(tile@data,consensus_frame,all=T)
plot(tile,color="consensus",colorPalette = pastel.colors(100), size = 2)

You must enable Javascript to view this page properly.

save.image("ITCs.RData")